var flgChk=false;
$(function(){
	$('.Search_Results').hover(function() {

        $(this).addClass('onhover');

      }, function() {

        $(this).removeClass('onhover');

      });

        $('.Search_Results').click(function() {
            if (flgChk==false)
                {
            
            if (this.getElementsByTagName('INPUT')[0].checked==false)
                {
                    this.getElementsByTagName('INPUT')[0].checked=true;
                }
            else
            {
                this.getElementsByTagName('INPUT')[0].checked=false;
            }

           setFilter(2);
        }
        else
            {
                flgChk=false;
            }

        });

	});



$(document).ready(function()
		{
			$("#selectAllresult").click(function()
			{
				var para="";
                                var paraoverlay="";
                                var paranonspecies="";
                                var v=document.getElementsByName("selectResult");
                                for (i=0;i<v.length;i++)
                                    {

                                        v[i].checked=true;
                            if (v[i].id=="selectResult_sepecies_" + v[i].value)
                                {
                                        if (para!="")
						{
							para=para+","
						}
				para= para + v[i].value;

                                }
                                if (v[i].id=="selectResult_overlay_" + v[i].value)
                                {
                                        if (paraoverlay!="")
						{
							paraoverlay=paraoverlay+","
						}
				paraoverlay= paraoverlay + v[i].value;

                                }
                                if (v[i].id=="selectResult_nonspecies_" + v[i].value)
                                {
                                        if (paranonspecies!="")
						{
							paranonspecies=paranonspecies+","
						}
				paranonspecies= paranonspecies + v[i].value;

                                }
                                
                                    }
				
                                setFilter("1",para+"OLY"+paraoverlay+"OLY"+paranonspecies);
			});
		});



$(document).ready(function()
		{
			$("#unselectAllresult").click(function()
			{

                                var v=document.getElementsByName("selectResult");
                                for (i=0;i<v.length;i++)
                                    {
                                        v[i].checked=false;
                                    }


                                setFilter("1","");
			});
		});

function setFilter(flg,pav,year_para_val,rtval)
{
var chk=document.getElementsByName("selectResult");
var para="";
var paraoverlay="";
var paranonspecies="";

if (flg=="1")
    {
        var tm=pav.split("OLY", pav.length);
        if (tm[0]==undefined)
            para="";
        else
            para=tm[0];
        
        if (tm[1]==undefined)
            paraoverlay="";
        else
            paraoverlay=tm[1];

        if (tm[2]==undefined)
            paranonspecies="";
        else
            paranonspecies=tm[2];

    }
else if (flg=="2")
    {
for (var i=0; i < chk.length; i++)
	   {
			if (chk[i].checked==true && chk[i].id=="selectResult_sepecies_" + chk[i].value)
			{
				if (para!="")
						{
							para=para+","
						}
				para= para + chk[i].value;
                                
			}
                        if (chk[i].checked==true && chk[i].id=="selectResult_overlay_" + chk[i].value)
			{
				if (paraoverlay!="")
						{
							paraoverlay=paraoverlay+","
						}
				paraoverlay= paraoverlay + chk[i].value;
                                
			}
                        if (chk[i].checked==true && chk[i].id=="selectResult_nonspecies_" + chk[i].value)
			{
				if (paranonspecies!="")
						{
							paranonspecies=paranonspecies+","
						}
				paranonspecies= paranonspecies + chk[i].value;

			}


		}
    }
    if (rtval!=undefined && rtval==true)
        {
            return para+"OLY"+paraoverlay;
        }
            setSessionforhistory(para+"OLY"+paraoverlay+"OLY"+paranonspecies);

            LoadData(para+"OLY"+paraoverlay+"OLY"+paranonspecies);


          setOverlayImage(map,paraoverlay);


     if((para!=null && para!="") || (paranonspecies!=null && paranonspecies!=""))
         {loadMarker(map,para+"OLY"+paranonspecies);} else {loadMarker(map,"");}


     
   
   // Calls the Chart function on click of each checkbox from right panel
   if($("#reportarea").is(":visible")==true){DrawChart(para,year_para_val);}
}

function tbvalue(obj)
{

}

function setSessionforhistory(str)
{

var history_species;
var history_overlay;
var history_nonspecies;
var tm=str.split("OLY",str.length);

history_species=tm[0];
history_overlay=tm[1];
history_nonspecies=tm[2];

if (history_species!="" )
    {
        
        if (window.sessionStorage.getItem('history')!=null && window.sessionStorage.getItem('history')!="")
            {

                    if(window.sessionStorage.getItem('history').match(history_species)==null)
                        {window.sessionStorage.setItem('history',window.sessionStorage.getItem('history') + ","+ history_species);}
                
            }
            else
            {
                
                
                    window.sessionStorage.setItem('history',history_species);
                

            }


}

if (history_overlay!="")
    {

        if (window.sessionStorage.getItem('history_overlay')!=null && window.sessionStorage.getItem('history_overlay')!="")
            {

                    if(window.sessionStorage.getItem('history_overlay').match(history_overlay)==null)
                        {window.sessionStorage.setItem('history_overlay',window.sessionStorage.getItem('history_overlay') + ","+ history_overlay);}

            }
            else
            {


                    window.sessionStorage.setItem('history_overlay',history_overlay);


            }


}
if (history_nonspecies!="" )
    {

        if (window.sessionStorage.getItem('nonspecies')!=null && window.sessionStorage.getItem('nonspecies')!="")
            {

                    if(window.sessionStorage.getItem('nonspecies').match(history_nonspecies)==null)
                        {window.sessionStorage.setItem('nonspecies',window.sessionStorage.getItem('nonspecies') + ","+ history_nonspecies);}

            }
            else
            {


                    window.sessionStorage.setItem('nonspecies',history_nonspecies);


            }


}
   
}
function LoadData(selectedvalues)
{



                                 $("#citation").html('<img src="/images/loading/loading9.gif">');
				$.post("http://"+location.hostname+"/citation/Index", {search: selectedvalues}, function(data) {
                                $("#citation").html(data);
                                });
}


function showAttributeReportAllLocation()
{
    var para="";

    var v=$("span[name=searchLocationName]");

    for (i=0;i<v.length;i++)
        {

            if (para.search(v[i].innerHTML)==-1)
                {

            if (para!="")
                    {
                            para=para+","
                    }

    para= para + v[i].innerHTML;
                }
    }
    
    showattributereport(para);
}
$(function() {
		$("#ViewAttributeButton,#unselectAllresult,#locationattributereportbtn,#selectAllresult,#downloadexceldata,#atrb").button();
                

	});